<?php
class Mail extends CI_Controller {
	public function __construct() {
		parent::__construct ();
		// 登录校验
		$this->common->check_login ();
		$this->load->helper ( array (
				'form',
				'url' ,
				'system'
		) );
	}
	
	// 留言
	public function index($page=1) {
		$perpage=10;
		
		if($page==0){
			$page=1;
		}
		
		$this->load->model ( 'message_model' );
		$data['result'] = $this->message_model->out_list_all($page,$perpage,$_SESSION ['user'] ['id']);
		$data['data_count']=$this->message_model->out_list_all_count($_SESSION ['user'] ['id']);
		$data['multi']=multi($data['data_count'],$perpage,$page,site_url('mail/index/?'),'?');
		
		$data ['left'] = $this->load->view ( 'left', '', TRUE );
		$data ['menu'] = $this->load->view ( 'menu', '', TRUE );
		
		$data ['mail_num'] = $this->message_model->mail_num ( $_SESSION ['user'] ['id'] );
		
		$this->load->view ( 'mail', $data );
	}
	
	// 留言
	public function message() {
		if(empty($_POST['title']) || empty($_POST['content']))
		{
			exit ( $this->common->alert_msg_goback ( '标题或内容不能为空' ) );
		}
		$this->load->model ( 'message_model' );
		$result = $this->message_model->message_insert ( $_SESSION ['user'] ['id'] );
		
		if ($result) {
			exit ( $this->common->alert_msg_url ( '留言成功', site_url ( 'mail' ) ) );
		} else {
			exit ( $this->common->alert_msg_goback ( '留言失败' ) );
		}
	}
}